import Vue from 'vue'
import Router from 'vue-router'


import Layout from "@/layout"
Vue.use(Router)

export const constantRoutes = [
    {
        // 登录
        path: '/login',
        component: () => import('@/views/login'),
        hidden: true
    },
    {
        // 首页
        path: "",
        component: Layout,
        redirect: "/index",
        //二级路由
        children:[
            {
                path: '/index',
                name:"Index",
                component: () => import('@/views/index'),
                meta: {title: '首页', icon: 'dashboard', affix: true}
            }
        ]

    },
]

// 防止连续点击多次路由报错
let routerPush = Router.prototype.push;
let routerReplace = Router.prototype.replace;
// push
Router.prototype.push = function push(location) {
    return routerPush.call(this, location).catch(err => err)
}
// replace
Router.prototype.replace = function push(location) {
    return routerReplace.call(this, location).catch(err => err)
}

export default new Router({
    mode: 'history', // 去掉url中的#
    scrollBehavior: () => ({y: 0}),
    routes: constantRoutes
})
